package com.clouddisk.user.controller;

import com.clouddisk.common.context.UserContext;
import com.clouddisk.common.response.Result;
import com.clouddisk.user.dto.UserDTO;
import com.clouddisk.user.dto.UserLoginDTO;
import com.clouddisk.user.dto.UserRegisterDTO;
import com.clouddisk.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {
    
    private final UserService userService;
    
    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public Result<UserDTO> register(@RequestBody @Valid UserRegisterDTO registerDTO) {
        return Result.success(userService.register(registerDTO));
    }
    
    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public Result<String> login(@RequestBody @Valid UserLoginDTO loginDTO) {
        return Result.success(userService.login(loginDTO));
    }
    
    @Operation(summary = "获取当前用户信息")
    @GetMapping("/current")
    public Result<UserDTO> getCurrentUser() {
        return Result.success(userService.getUserInfo(UserContext.getCurrentUserId()));
    }
    
    @Operation(summary = "获取指定用户信息")
    @GetMapping("/{id}")
    public Result<UserDTO> getUserInfo(@PathVariable Long id) {
        return Result.success(userService.getUserInfo(id));
    }
} 